
import matplotlib.pyplot as plt
import numpy as np

# 使用pie()方法绘制饼图
def fun1():
    y = np.array([35, 25, 25, 15])

    plt.pie(y)
    plt.show()

# 设置饼图各个扇形的标签与颜色
def fun2():
    y = np.array([35, 25, 25, 15])

    plt.pie(y,
            labels=['Java', 'Python', 'C++', 'JavaScript'],
            colors=['red', 'green', 'blue', 'yellow'])

    plt.title("Python Pie Test")
    plt.show()

# 突出显示第二个扇形，并格式化输出百分比
def fun3():
    # 数据
    sizes = [15, 30, 45, 10]
    # 饼图的标签
    labels = ['Java', 'Python', 'C++', 'JavaScript']
    # 饼图的颜色
    colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
    # 突出显示第二个扇形
    explode = (0, 0.1, 0, 0)

    # 绘制饼图
    plt.pie(sizes, explode=explode, labels=labels, colors=colors,
            autopct='%1.1f%%', shadow=True, startangle=90)

    plt.title("Python Pie Test")
    plt.show()

def fun4():
    y = np.array([35, 25, 25, 15])

    plt.pie(y,
            labels=['Java', 'Python', 'C++', 'JavaScript'],
            colors=["#d5695d", "#5d8ca8", "#65a479", "#a564c9"],
            explode=(0, 0.2, 0, 0),
            autopct='%.2f%%')
    plt.title('Python Pie Test')
    plt.show()

if __name__ == '__main__':
    fun4()